/**
 * 栈（stack）又名堆栈，它是一种运算受限的线性表
 * 限定仅在表尾进行插入和删除操作的线性表，这一端被称为栈顶，相对地，把另一端称为栈底
 * 向一个栈插入新元素又称作进栈、入栈或压栈，它是把新元素放到栈顶元素的上面，使之成为新的栈顶元素
 * 从一个栈删除元素又称作出栈或退栈，它是把栈顶元素删除掉，使其相邻的元素成为新的栈顶元素
 */
 class Stack {
  constructor() {
      this.data = [];
      this.top = 0;
  }
  push(node) {
      this.data[this.top++] = node;
      console.log('==',this.data);
  }
  pop() {
      return this.data[--this.top];
  }
  peek() {
      return this.data[this.top - 1];
  }
  size() {
      return this.top;
  }
  clear() {
      this.top = 0;
  }
}

const stack = new Stack();
stack.push('1');
stack.push('2');
stack.push('3');
console.log('stack.size()', stack.size());
console.log('stack.peek', stack.peek());
console.log('stack.pop()', stack.pop());
console.log('stack.peek()', stack.peek());
stack.push('4');
console.log('stack.peek', stack.peek());
stack.clear();
console.log('stack.size', stack.size());
stack.push('5');
console.log('stack.peek', stack.peek());